<template>
    <div>
    <Form
            ref="form"
            :form-items="formItems"
            :init-data-url="$baseURL.composite + '/composite/railwaystation/' + $route.params.id"
    ></Form>
    <BaiduMapLocationDialog ref="baiduMapLocationDialog" v-on:selectLocation="(location)=>{
    $refs.form.setFormItem('longitude',location.longitude)
    $refs.form.setFormItem('latitude',location.latitude)
    }">
    </BaiduMapLocationDialog>
    </div>
</template>

<script>
    import Form from '../../../../common-util/src/components/page/Form.vue'
    import BaiduMapLocationDialog from '../../../../common-util/src/components/common/BaiduMapLocationDialog.vue'
    export default {
        components:{
            Form,
            BaiduMapLocationDialog
        },
        data(){
            return {
                formItems:[
                    {
                        field: {
                            name: 'code'
                        },
                        element:{
                            label: '编码',
                            disabled: true
                        }
                    },
                    {
                        field: {
                            name: 'name'
                        },
                        element:{
                            label: '名称',
                            required: true
                        }
                    },
                    {
                        field: {
                            name: 'seq'
                        },
                        element:{
                            label: '第几站',
                            type: 'inputNumber',
                            required: true
                        }
                    },
                    {
                        field: {
                            name: 'railwayId'
                        },
                        element:{
                            label: '铁路线',
                            required: true,
                            type: 'select',
                            select: {
                                url: this.$baseURL.composite + '/composite/railway/list'
                            }
                        }
                    },
                    {
                        field: {
                            name: 'provinceAreaId'
                        },
                        element:{
                            label: '省',
                            required: true,
                            type: 'select',
                            select: {
                                url: this.$baseURL.base + '/base/area/list?parentCode=country_zhongguo&typeDictCode=province'
                            }
                        }
                    },
                    {
                        field: {
                            name: 'cityAreaId'
                        },
                        element:{
                            label: '城市',
                            required: true,
                            disabled: (form)=>{
                                return !form.provinceAreaId
                            },
                            type: 'select',
                            select: {
                                url: (form)=>{
                                    if (!form.provinceAreaId) {
                                        return null
                                    }
                                    return this.$baseURL.base + '/base/area/list?parentId=' + form.provinceAreaId
                                }
                            }
                        }
                    },
                    {
                        field: {
                            name: 'districtAreaId'
                        },
                        element:{
                            label: '区',
                            required: true,
                            disabled: (form)=>{
                                return !form.cityAreaId
                            },
                            type: 'select',
                            select: {
                                url: (form)=>{
                                    if (!form.cityAreaId) {
                                        return null
                                    }
                                    return this.$baseURL.base + '/base/area/list?parentId=' + form.cityAreaId
                                }
                            }
                        }
                    },

                    {
                        field: {
                            name: 'firstStartAt'
                        },
                        element:{
                            label: '首班发车时间',
                            type: 'date',
                            date:{
                                type: 'time'
                            },
                        }
                    },
                    {
                        field: {
                            name: 'lastEndAt'
                        },
                        element:{
                            label: '末班结束时间',
                            type: 'date',
                            date:{
                                type: 'time'
                            },
                        }
                    },
                    {
                        field: {
                            name: 'longitude'
                        },
                        element:{
                            label: '经度',
                            type: 'inputButton',
                            inputButton:{
                                bClick:this.longitudeBtnClick
                            },
                        }
                    },
                    {
                        field: {
                            name: 'latitude'
                        },
                        element:{
                            label: '纬度',
                        }
                    },
                    {
                        field: {
                            name: 'runUpDuration'
                        },
                        element:{
                            label: '上行运行时间(分)',
                        }
                    },
                    {
                        field: {
                            name: 'runDownDuration'
                        },
                        element:{
                            label: '下行运行时间(分)',
                        }
                    },
                    {
                        field: {
                            name: 'stayUpDuration'
                        },
                        element:{
                            label: '上行停站时间(分)',
                        }
                    },
                    {
                        field: {
                            name: 'stayDownDuration'
                        },
                        element:{
                            label: '下行停站时间(分)',
                        }
                    },
                    {
                        field: {
                            name: 'remark'
                        },
                        element:{
                            label: '备注',
                        }
                    },
                    {
                        field: {
                            name: 'version'
                        }
                    },
                    {
                        element:{
                            type: 'button',
                            button:[
                                {
                                    action: 'submit',
                                    requestMethod:'put',
                                    url: this.$baseURL.composite + '/composite/railwaystation/' +this.$route.params.id,
                                    label: '保存'
                                },
                                {
                                    action: 'reset',
                                    label: '重置',
                                    type: 'default'
                                }
                            ]
                        }
                    }
                ]
            }
        },
        mounted(){
        },
        methods:{
            longitudeBtnClick () {
                let form =this.$refs.form.getFormData()
                this.$refs.baiduMapLocationDialog.show(form.longitude,form.latitude)

            },
        }
    }
</script>

<style scoped>

</style>